﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using UniMana.Utils.Controls;
using System.Windows.Forms;
using System.Data;
using UniMana.Data;

namespace UniMana.Data
{
    public class Training_SubjectRelationshipInfo
    {
        private bds m_bds = new bds();
        private DBMain m_data = new DBMain();
        private bool m_bExistInDB = true;

        public bool ExistInDataBase
        {
            get { return m_bExistInDB; }
        }
        public Training_SubjectRelationshipInfo(int _iSubjectKey1, int _iSubjectKey2)
        {
            var Iquery = m_data.m_DCSave.Training_SubjectRelationships.Where(p => p.Training_SubjectKey1 == _iSubjectKey1 && p.Training_SubjectKey2 == _iSubjectKey2);
            this.m_bds.DataSource = Iquery;
            var Row = Iquery.FirstOrDefault();
            this.m_bExistInDB = true;
            if (Row == null)
            {
                this.m_bExistInDB = false;
                Row = new Training_SubjectRelationship();
                Row.Training_SubjectKey1 = _iSubjectKey1;
                Row.Training_SubjectKey2 = _iSubjectKey2;
                this.m_bds.Add(Row);
                this.m_bds.MoveLast();
            }
        }

        public Training_SubjectRelationshipInfo(int _iKey)
        {
            var iQuery = m_data.m_DCSave.Training_SubjectRelationships.Where(p => p.Training_SubjectRelationshipKey == _iKey);
            this.m_bds.DataSource = iQuery;
            var Row = iQuery.FirstOrDefault();
            this.m_bExistInDB = true;
            if (Row == null)
            {
                this.m_bExistInDB = false;
                Row = new Training_SubjectRelationship();
                this.m_bds.Add(Row);
                this.m_bds.MoveLast();
            }
        }
        public Training_SubjectRelationship Properties
        {
            get { return m_bds.Current as Training_SubjectRelationship; }
        }

        public void Delete()
        {
            this.m_bds.DeleteCurrent();
        }

        public void Save()
        {
            this.m_bds.EndEdit();
            this.m_data.m_DCSave.SubmitChanges();
        }
    }
}
